﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Mbs.Windows
{
    /// <summary>
    /// Clipboard service class
    /// </summary>
    public sealed class ClipboardService
    {
        /// <summary>
        /// set data
        /// </summary>
        /// <param name="data"></param>
        public static void Set(object data)
        {
            Clipboard.SetDataObject(data, true);
        }

        /// <summary>
        /// get data
        /// </summary>
        /// <typeparam name="TTarget"></typeparam>
        /// <returns></returns>
        public static T Get<T>()
        {
            var data = Clipboard.GetDataObject();
            if (data == null)
                return default(T);

            return (T)data.GetData(typeof(T));
        }

        public static bool Contains(Type type)
        {
            var data = Clipboard.GetDataObject();
            if (data == null || type == null)
                return false;
            return data.GetDataPresent(type);
        }
        /// <summary>
        /// is contains data
        /// </summary>
        /// <typeparam name="TTarget"></typeparam>
        /// <returns></returns>
        public static bool Contains<T>()
        {
            var data = Clipboard.GetDataObject();
            if (data == null)
                return false;
            return data.GetDataPresent(typeof(T));
        }

        public static bool ContainsImage()
        {
            return Clipboard.ContainsImage();
        }

        public static Image GetImage()
        {
            return Clipboard.GetImage();
        }
    }
}
